//
//  CancelAccountAlertView.m
//  Peso Guide
//
//  Created by macbook on 2025/6/15.
//

#import "CancelAccountAlertView.h"

@interface CancelAccountAlertView ()

@property (nonatomic, strong) UIView *grayView;
@property (nonatomic, strong) UIImageView *backImg;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *confirmButton;
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation CancelAccountAlertView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _grayView = [PesoKit createViewWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight) backGroundColor:[UIColor colorWithHexString:@"#000000" alpha:0.7]];
        [self addSubview:_grayView];
        
        _backImg = [PesoKit createImageViewWithFrame:CGRectMake((KScreenWidth-301)/2.0, (KScreenHeight-411)/2.0-20, 301, 411) imageNamed:@"ic_identity_alert_back"];
        _backImg.userInteractionEnabled = YES;
        _backImg.clipsToBounds = YES;
        _backImg.layer.cornerRadius = 15.0f;
        [self addSubview:_backImg];
        
        _titleLabel = [PesoKit createLabelWithFrame:CGRectMake(0, 0, _backImg.width, 60) backGroundColor:[UIColor clearColor] text:[Lang set:@"Tips"] textColor:ColorHex(@"#000000") font:FONT(FontWeightStyleMedium, 20)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [_backImg addSubview:_titleLabel];
        
        _contentLabel = [PesoKit createLabelWithFrame:CGRectMake(28, 68, _backImg.width-56, _backImg.height-68-44-32-10) backGroundColor:[UIColor clearColor] text:[Lang set:@"Are you sure you want to cancel your account"] textColor:ColorHex(@"#0E1D31") font:FONT(FontWeightStyleRegular, 16)];
        _contentLabel.numberOfLines = 0;
        [_backImg addSubview:_contentLabel];
        
        _confirmButton = [PesoKit createButtonWithFrame:CGRectMake((_backImg.width-214)/2.0, _backImg.height-32-44, 214, 44) backGroundColor:ColorHex(@"#FE7133") title:[Lang set:@"Confirm"] titleColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleMedium, 18)];
        [_confirmButton addTarget:self action:@selector(confirmButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _confirmButton.clipsToBounds = YES;
        _confirmButton.layer.cornerRadius = 22.0f;
        [_backImg addSubview:_confirmButton];
        
        _closeButton = [[UIButton alloc] initWithFrame:CGRectMake((KScreenWidth-26)/2.0, _backImg.bottom+16, 26, 26)];
        [_closeButton setBackgroundImage:[UIImage imageNamed:@"ic_identity_close"] forState:0];
        [_closeButton addTarget:self action:@selector(closeButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_closeButton];
    }
    return self;
}

- (void)confirmButtonClick {
    [self removeFromSuperview];
    
    [[AWHttpService service] getWithUrl:@"/trains/unnested" params:@{} succ:^(id  _Nonnull responseObject) {
        if (SUCCESS) {
            NSString *order = [NSString stringWithFormat:@"%@",[responseObject safeObjectForKey:@"order"]];
            [SVProgressHUD showSuccessWithStatus:order];
            [SVProgressHUD dismissWithDelay:3.0f];

            
            [self performSelector:@selector(tologin111) withObject:nil afterDelay:2];
        }
    } fail:^(NSInteger errorType, id  _Nonnull error) {
        
    }];
}

- (void)closeButtonClick {
    [self removeFromSuperview];
}

- (void)tologin111 {
    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"user_token"];
    [[AppTools getCurrentVC].navigationController popToRootViewControllerAnimated:YES];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
